package com.virtualperson.exception;

import com.virtualperson.dto.ImageGenerationResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ImageValidationException.class)
    public ImageGenerationResponse handleImageValidationException(ImageValidationException e) {
        log.error("图片验证失败", e);
        ImageGenerationResponse response = new ImageGenerationResponse();
        response.setSuccess(false);
        response.setErrorMessage(e.getMessage());
        return response;
    }

    @ExceptionHandler(Exception.class)
    public ImageGenerationResponse handleException(Exception e) {
        log.error("系统异常", e);
        ImageGenerationResponse response = new ImageGenerationResponse();
        response.setSuccess(false);
        response.setErrorMessage("系统异常: " + e.getMessage());
        return response;
    }
} 